﻿
Public Class getElementById
    Public Const functionName As String = "gei"

    Public Shared Sub register(ByVal inlineScript As inlineScript)
        assert(Not inlineScript Is Nothing, "inlineScript is nothing.")
        inlineScript.addscript("getElementById", "function " + functionName + "(i){" + _
                               "return document.getElementById(i);}")
    End Sub

    Public Shared Function invoke(ByVal inlineScript As inlineScript, ByVal id As String, _
                                  Optional ByRef actionTarget As String = Nothing) As String
        If Not inlineScript Is Nothing Then
            register(inlineScript)
        End If

        assert(Not isemptystring(id), "id is empty string.")
        actionTarget += functionName + "(" + id + ")"

        Return actionTarget
    End Function
End Class

Public Class getValueById
    Public Const oper As String = "value"

    Public Shared Function invoke(ByVal inlineScript As inlineScript, ByVal id As String, _
                                  Optional ByRef actionTarget As String = Nothing) As String
        actionTarget += getElementById.invoke(inlineScript, id) + "." + oper
        Return actionTarget
    End Function
End Class

Public Class createElement
    Public Const functionName As String = "cem"

    Public Shared Sub register(ByVal inlineScript As inlineScript)
        assert(Not inlineScript Is Nothing, "inlineScript is nothing.")
        inlineScript.addscript("createElement", "function " + functionName + "(i){" + _
                               "return " + document.name(inlineScript) + ".createElement(i);}")
    End Sub

    Public Shared Function invoke(ByVal inlineScript As inlineScript, ByVal tagName As String, _
                                  Optional ByRef actionTarget As String = Nothing) As String
        If Not inlineScript Is Nothing Then
            register(inlineScript)
        End If

        actionTarget += functionName + "(" + tagName + ")"
        Return actionTarget
    End Function
End Class

Public Class submitById
    Public Const oper As String = "submit()"

    Public Shared Function invoke(ByVal inlineScript As inlineScript, ByVal id As String, _
                                  Optional ByRef actionTarget As String = Nothing) As String
        actionTarget += getElementById.invoke(inlineScript, id) + "." + oper
        Return actionTarget
    End Function
End Class

Public Class onsubmitById
    Public Const oper As String = "onsubmit()"

    Public Shared Function invoke(ByVal inlineScript As inlineScript, ByVal id As String, _
                                  Optional ByRef actionTarget As String = Nothing) As String
        actionTarget += getElementById.invoke(inlineScript, id) + "." + oper
        Return actionTarget
    End Function
End Class

Public Class document
    Private Const _name As String = "d"

    Public Shared Sub register(ByVal inlineScript As inlineScript)
        assert(Not inlineScript Is Nothing)
        var.invoke(inlineScript, _name, "document")
    End Sub

    Public Shared Function name(ByVal inlineScript As inlineScript, _
                                Optional ByRef actionTarget As String = Nothing) As String
        If Not inlineScript Is Nothing Then
            register(inlineScript)
        End If

        actionTarget += _name
        Return actionTarget
    End Function
End Class

'before the body is loaded, it is always null
#If RETIRED Then
Public Class document_body
    Private Const _name As String = "b"

    Public Shared Sub register(ByVal inlineScript As inlineScript)
        assert(Not inlineScript Is Nothing)
        var.invoke(inlineScript, _name, document.name(inlineScript) + ".body")
    End Sub

    Public Shared Function name(ByVal inlineScript As inlineScript, _
                                Optional ByRef actionTarget As String = Nothing) As String
        If Not inlineScript Is Nothing Then
            register(inlineScript)
        End If

        actionTarget += _name
        Return actionTarget
    End Function
End Class
#End If

Public Class appendChild
    Private Const functionName As String = "apc"

    Public Shared Sub register(ByVal inlineScript As inlineScript)
        assert(Not inlineScript Is Nothing)
        inlineScript.addscript(functionName, "function " + functionName + "(p,c){p.appendChild(c);}")
    End Sub

    Public Shared Function invoke(ByVal inlineScript As inlineScript, _
                                  ByVal parent As String, ByVal child As String, _
                                  Optional ByRef actionTarget As String = Nothing) As String
        If Not inlineScript Is Nothing Then
            register(inlineScript)
        End If

        actionTarget += functionName + "(" + parent + "," + child + ")"
        Return actionTarget
    End Function
End Class